﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Project_2._2.Models;
using System.Web.Security;

namespace Project_2._2.Extra
{
    public class Common
    {
        private QuanLyThueXeEntities db = new QuanLyThueXeEntities();
        
        public Boolean CheckUserName(string username)
        {
            var ps = (from p in db.People where p.isDelete == false select p.TenDangNhap).ToList();
            for (int i = 0; i < ps.Count; i++)
            {
                if (ps[i].CompareTo(username) == 0)
                {
                    return true;
                    break;
                }
            }
            return false;
        }

        public Boolean CheckEmail(string email)
        {
            var ps = (from p in db.People where p.isDelete == false select p.Email).ToList();
            for (int i = 0; i < ps.Count; i++)
            {
                if (ps[i].CompareTo(email) == 0)
                {
                    return true;
                    break;
                }
            }
            return false;
        }

        public bool CheckLogin(string username, string password)
        {
            var ps = (from p in db.People where p.isDelete == false select p).ToList();
            string Pass = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
            for (int i = 0; i < ps.Count; i++)
            {
                if (ps[i].TenDangNhap == username && ps[i].MatKhau == Pass)
                {
                    return true;
                    break;
                }
            }

            return false;
        }

        public bool CheckUserType( string username)
        {
            var ps = (from p in db.People where p.TenDangNhap.Equals(username) select p).FirstOrDefault();
            if (ps.RoleId == 1)
            {
                return true;
            }
            else
                return false;
           
        }
    }

        
}